package com.study.yangfei.mystudy.activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import com.study.yangfei.mystudy.R;
import com.study.yangfei.mystudy.utils.TimingLoggerYF;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class TimingLoggerActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timing_logger);

        boolean islog = Log.isLoggable("TimingLogger", Log.INFO);
        TimingLoggerYF timings = new TimingLoggerYF("TimingLogger", "methodA");

        testLongTimeRun();
        timings.addSplit("testLongTimeRun");

        writeToExternalStorage();
        timings.addSplit("writeToExternalStorage");

//        testNetwork();
//        timings.addSplit("testNetwork");
        timings.dumpToLog();
    }

    public void writeToExternalStorage() {
        File externalStorage = Environment.getExternalStorageDirectory();
        File destFile = new File(externalStorage, "dest.txt");
        try {
            OutputStream output = new FileOutputStream(destFile, true);
            output.write("droidyue.com".getBytes());
            output.flush();
            output.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void testLongTimeRun(){
        double sum = 0;
        for(int i=0;i<1000*10000;i++){
            sum = sum + (double)i/5.123456f;
        }
        Log.e("StrictModeyf", "sum = "+sum);
    }

}
